#include "test.h"

Test::Test():
    QObject()
{
    name = "";
    countVis = 0;
    currentTestNodeId = 0;
}

Test::Test(const Test &test):
    QObject()
{
    this->name = test.name;
    this->countVis = test.countVis;
    this->nodeList = test.nodeList;
    this->currentTestNodeId = test.currentTestNodeId;
}

void Test::setName(const QString &name)
{
    this->name = name;
}

void Test::addNode(TestNode node)
{
    nodeList.append(node);
}

void Test::setCountVis(quint32 countVis)
{
    this->countVis = countVis;
}

void Test::setNodeList(QList<TestNode> nodeList)
{
    this->nodeList = nodeList;
}

void Test::setCurrentTestNodeId(quint32 id)
{
    currentTestNodeId = id;
}

QString Test::getName() const
{
    return name;
}

TestNode Test::getTestNodeById(quint32 id)
{
    quint32 i = id;
    if(id >= count())
        i = count() - 1;
    return nodeList.at(i);
}

bool Test::next(TestNode &testNode)
{
    if(currentTestNodeId >= count())
        return false;
    testNode = nodeList.at(currentTestNodeId);
    currentTestNodeId++;
    return true;
}

quint32 Test::count() const
{
    return nodeList.count();
}

quint32 Test::getCountVis() const
{
    return countVis;
}

QDataStream &operator <<(QDataStream &out, const Test &test)
{
    out << test.getName() << quint32(test.getCountVis()) << test.getNodeList();
    return out;
}

QDataStream &operator >>(QDataStream &in, Test &test)
{
    QString name = "";
    quint32 cVis = 0;
    QList<TestNode> nodeList;

    in >> name >> cVis >> nodeList;
    test.setName(name);
    test.setCountVis(cVis);
    test.setNodeList(nodeList);

    return in;
}

QList<TestNode> Test::getNodeList() const
{
    return nodeList;
}

quint32 Test::getCurrentTestNodeId() const
{
    return currentTestNodeId;
}

Test &Test::operator =(const Test &test)
{
    name = test.name;
    countVis = test.countVis;
    nodeList = test.nodeList;
    currentTestNodeId = test.currentTestNodeId;
    return *(this);
}
